import pickle
from .models import *
from django.http import JsonResponse
from django.db import models


def query_json(models: models, queryList: list):
    '''
    查询并序列化为json的http对象
    '''
    # 定义查询字段
    qs = models.objects.values_list(*queryList)
    # 生成查询语句
    reloaded_qs = models.objects.all()
    # 查询数据
    reloaded_qs.query = pickle.loads(pickle.dumps(qs.query))
    # 解析装载返回
    return JsonResponse(list(reloaded_qs), safe=False)